package com.farm.learn.domain.ex;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.farm.learn.domain.ClassChapter;
import com.farm.learn.domain.ClassHour;
import com.farm.learn.domain.Playtime;
import com.farm.sfile.domain.FileBase;

public class HourView {
	//
	private ClassHour hour;
	private ClassView classview;
	private String viewurl;
	private FileBase filebase;
	private List<HourView> hours;
	private ClassChapter chapter;
	private Playtime playtime;
	// 可以預覽的課時
	private boolean viewAble = true;
	// pdf转换的imgs数量
	private int pinum = 0;

	public boolean isViewAble() {
		return viewAble;
	}
	
	public Playtime getPlaytime() {
		return playtime;
	}

	public void setPlaytime(Playtime playtime) {
		this.playtime = playtime;
	}

	private void setViewAble(boolean viewAble) {
		this.viewAble = viewAble;
	}

	public int getPinum() {
		return pinum;
	}

	public void setPinum(int pinum) {
		this.pinum = pinum;
	}

	public ClassHour getHour() {
		return hour;
	}

	public void setHour(ClassHour hour) {
		this.hour = hour;
	}

	public ClassView getClassview() {
		return classview;
	}

	public void setClassview(ClassView classview) {
		this.classview = classview;
	}

	public String getViewurl() {
		return viewurl;
	}

	public void setViewurl(String viewurl) {
		this.viewurl = viewurl;
	}

	public FileBase getFilebase() {
		return filebase;
	}

	public void setFilebase(FileBase filebase) {
		this.filebase = filebase;
	}

	public List<HourView> getHours() {
		return hours;
	}

	public void setHours(List<HourView> hours) {
		this.hours = hours;
	}

	public ClassChapter getChapter() {
		return chapter;
	}

	public void setChapter(ClassChapter chapter) {
		this.chapter = chapter;
	}

	/**
	 * 初始化课时是否可以预览的属性
	 * 
	 * @param hour
	 * @return
	 */
	public static HourView initHourViewAble(HourView hourview) {
		Set<Object> viewAbleHours = new HashSet<>();
		for (HourView hour : hourview.getHours()) {
			if (viewAbleHours.size() < hour.getClassview().getClasst().getViewnum()) {
				viewAbleHours.add(hour.getHour().getId());
			}
		}
		for (HourView hour : hourview.getHours()) {
			if (viewAbleHours.contains(hour.getHour().getId())) {
				hour.setViewAble(true);
			} else {
				hour.setViewAble(false);
			}
		}
		return hourview;
	}

	/**
	 * 初始化课时是否可以预览的属性
	 * 
	 * @param classView
	 * @return
	 */
	public static ClassView initClassHourAble(ClassView classView) {
		Set<Object> viewAbleHours = new HashSet<>();
		for (ClassHour hour : classView.getHours()) {
			if (viewAbleHours.size() < classView.getClasst().getViewnum()) {
				viewAbleHours.add(hour.getId());
			}
		}
		for (ClassHour hour : classView.getHours()) {
			if (viewAbleHours.contains(hour.getId())) {
				hour.setViewAble(true);
			} else {
				hour.setViewAble(false);
			}
		}
		return classView;
	}
}
